home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / XDME / Src / Key / KeyCom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  16.4 KB  |  782 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     keycom.c
  5.  
  6.     DESCRIPTION
  7.     command interface for keyboard-control with key functions
  8.  
  9.     NOTES
  10.     for interface with [X]DME version < 1.70
  11.         all functions in this module make use of av[] (readonly)
  12.     extensively uses keyhashes.c
  13.  
  14.     BUGS
  15.     plenty - but where
  16.  
  17.     TODO
  18.  
  19.  
  20.     EXAMPLES
  21.  
  22.     description of the user-commands:
  23.  
  24.     the commands below might get other names;
  25.     if so, please update their descriptions according
  26.     to the names they are used in command.c
  27.  
  28. *!***************************************************************************
  29. *!
  30. *!  KEYS:
  31. *!  ****
  32. *!
  33. *!  the following commands allow access to [X]DME's keymappings
  34. *!  that way it is possible for each user to create an individual
  35. *!  UI for "his" [X]DME, for "his" programming language and for
  36. *!  his wishes.
  37. *!
  38. *! >MAP   key command    (will be "MAP key command help")
  39. *! >UNMAP key
  40. *!
  41. *!    with these commands YOu can modify the keytable:
  42. *!    MAP adds or modifies an existing key-entry to the keytable
  43. *!    UNMAP deletes an existing key-entry
  44. *!
  45. *!    key consists of a set of QUALIFIERS, a "-" and one code-
  46. *!    specification (both case sensitive)
  47. *!    the qualifiers are:
  48. *!        s == any shift (caps-lock with alpha-keys)
  49. *!        c == control
  50. *!        a == any alt
  51. *!        A == any amiga
  52. *!        L == left mouse button
  53. *!        M == middle mouse button
  54. *!        R == right mouse button
  55. *!        u == key-up ( release of a key )
  56. *!        x == extended qualifier x
  57. *!        y == extended qualifier y
  58. *!        z == extended qualifier z
  59. *!        r == repeat
  60. *!
  61. *!    the code-specification is one out of:
  62. *!      main keyboard:
  63. *!        [single lowercase character] == the key on you main keyboard - that shows it
  64. *!        [single uppercase alpha]     == the key on .... but that means a set s-qualifier
  65. *!
  66. *!      numeric keypad:
  67. *!        nk0 .. nk9        == numerik keypad 0..9
  68. *!        nk+|nk-|nk*|nk/|nk. == numerik keypad +,-,*,/,.
  69. *!
  70. *!        there are two more key on yor numerik keypad
  71. *!        with american|british mapping they are used as nk( and nk)
  72. *!        with most european mappings they are used as nk[ and nk]
  73. *!        with canadian mapping they are used as nk@ and nk°
  74. *!        if there is a standart mapping, that does map these keys
  75. *!        in another way, they are NOT supported yet. (please mail)
  76. *!
  77. *!      other special keys:
  78. *!        f1 .. f10       == Function keys
  79. *!        hel        == help-key
  80. *!        esc        == escape
  81. *!        del        == delete
  82. *!        bac|bs       == backspace ( <- )
  83. *!        tab        == tabulator
  84. *!        ent        == enter
  85. *!        spc|spa       == spacebar
  86. *!        up|dow|rig|lef == cursor keys
  87. *!
  88. *!        lmb|mmb|rmb    == mouse buttons
  89. *!        mmo        == mouse movement with a mousebutton pressed
  90. *!        ?m2|?m3|?m4    == (? in {lmr}) double/triple/qraduple clicks of a
  91. *!                  certain mouse button (times out!)
  92. *!
  93. *!    note that as mousebuttons can act for qualifiing as well as for
  94. *!    specifiing, the specifiing mousebutton must also be qualifiing
  95. *!    e.g L-rmb should not work, but LR-rmb should
  96. *!
  97. *!    note that certain keys may be used as dead-keys;
  98. *!    keys that are deading when pressed without qualifiers
  99. *!    are not accessible with that keyboard-interface
  100. *!    e.g. on german keyboards there is a key "'" next to "\"
  101. *!         which cannot be accessed
  102. *!    on the other hand, if a key is deading on a qualified level,
  103. *!    but not when pressed without qualifiers, You can remap it
  104. *!    e.g on german keyboards alt-f is deading, but -f not, so
  105. *!        You can access a-f; and if You map a-f to any function,
  106. *!        It looses it deading function for [X]DME
  107. *!        EXAMPLE:  <alt-f> <a> creates something like "á"
  108. *!        after a "MAP a-f (NULL)" the same key-sequence
  109. *!        creates a normal "a"
  110. *!
  111. *!    note that map soon is to expect another parameter:
  112. *!        the help-string that contains information 'bout the command
  113. *!
  114. *!    keys with the x|y|z-qualifiers set can not accessed immediately
  115. *!    first You must set the right extended qualifiers (see QUALIFIER
  116. *!    command), then You may press the remaining qualifiers and keys
  117. *!    these keys were introduced to allow something like the
  118. *!    CTL-X prefix of MicroEmacs
  119. *!
  120. *!    ATN! we check only up to three characters for code-specifiction
  121. *!        so e.g. -space is recognized as -spa some people
  122. *!        call this a feature, but in fact it is a BUG, as that
  123. *!        method avoids rexx-commands which start whose 3 first digits
  124. *!        are the same like a special key from being implicitely executed
  125. *!
  126. *! >QUALIFIER qualifierset
  127. *!
  128. *!    that command allows setting of certain qualifiers
  129. *!    independently to the qualifiers pressed manually on the keyboard
  130. *!    (see above) it is designed to allow multi-key-sequences
  131. *!
  132. *!    EXAMPLE:
  133. *!         MAP  c-x (QUALIFIER x)
  134. *!         MAP cx-a (SAVEOLD)
  135. *!        would cause the sequence <ctrl-x> <ctrl-a> calling SAVEOLD
  136. *!
  137. *! >KEYSAVE filename
  138. *!
  139. *!    save the keytable as a file that can be
  140. *!    read by KEYLOAD
  141. *!
  142. *! >KEYLOAD filename
  143. *!
  144. *!    clear the keytable and instead build a new
  145. *!    contents out of the file filename
  146. *!
  147. *!
  148. *!  KEYTABLES:
  149. *!  *********
  150. *!
  151. *!  the following commands do only make sense, if
  152. *!  You are using multiple keytables
  153. *!  at [X]DME's start a keytable called "default" is created;
  154. *!  for "normal" usage, that single strip may suffer.
  155. *!
  156. *!  Please note that the above MENU... commands apply to the
  157. *!  CURRENT keytable (and only to it)
  158. *!
  159. *! >USEKEYTABLE name
  160. *!
  161. *!    search for a certain keytable and use it as the current one
  162. *!
  163. *! >REMKEYTABLE
  164. *!
  165. *!    delete the current keytable, if it is not the only one
  166. *!
  167. *! >NEWKEYTABLE name
  168. *!
  169. *!    if there is already a keytable called name,
  170. *!        simply call USEKEYTABLE name
  171. *!    else create a new keytable called name and use it
  172. *!
  173. *!
  174.  
  175.     SEE ALSO
  176.     keyhashes.c keycodes.c keyaddes.c keycontrol.c
  177.  
  178.     INDEX
  179.  
  180.     HISTORY
  181.     14-Dec-92  b_null created
  182.     16-Dec-92  b_null some names updated & introduced currenthash
  183.     05-08-94   null added STATIC Command Interface
  184.     $Date: 94/07/06 12:06:48 $ last update
  185.  
  186. ******************************************************************************/
  187.  
  188. /**************************************
  189.         Includes
  190. **************************************/
  191. /* we do not need anythig else - I think */
  192. #define  KEY_INTERNAL            /* PATCH_NULL < 24-06-94 */
  193. #include "defs.h"
  194. #ifdef PATCH_NULL
  195. #include "COM.h"
  196. #endif
  197.  
  198.  
  199. /**************************************
  200.         Globale Variable
  201. **************************************/
  202. Prototype void do_map        (void);
  203. Prototype void do_unmap     (void);
  204. Prototype void do_keyload   (void);
  205. Prototype void do_keysave   (void);
  206. Prototype void do_qualifier (void);
  207. Prototype char*keyspectomacro(char*);
  208.  
  209. Prototype void do_new_keytable (void);
  210. Prototype void do_del_keytable (void);
  211. Prototype void do_use_keytable (void);
  212.  
  213. Prototype void*currenthash  (void);
  214.  
  215. /**************************************
  216.       Interne Defines & Strukturen
  217. **************************************/
  218. /* nothing */
  219.  
  220. /**************************************
  221.         Interne Variable
  222. **************************************/
  223. /* nothing */
  224.  
  225. /**************************************
  226.        Interne Prototypes
  227. **************************************/
  228. /* nothing */
  229.  
  230. /*****************************************************************************
  231.  
  232.     NAME
  233.     do_map
  234.  
  235.     PARAMETER
  236.     void
  237.  
  238.     RESULT
  239.     -/-
  240.  
  241.     RETURN
  242.     void
  243.  
  244.     DESCRIPTION
  245.     command interface for keyhashes/mapkey
  246.  
  247.     NOTES
  248.     for interface with [X]DME version < 1.70
  249.  
  250.     BUGS
  251.  
  252.     EXAMPLES
  253.  
  254.     SEE ALSO
  255.     do_unmap keyhashes/mapkey
  256.  
  257.     INTERNALS
  258.  
  259.     HISTORY
  260.     14-Dec-92  b_null created
  261.  
  262. ******************************************************************************/
  263.  
  264. void do_map (void)
  265. {
  266.     mapkey ( currenthash(), GetArg(1), GetArg(2), NULL );
  267. } /* do_map */
  268.  
  269.  
  270.  
  271. /*****************************************************************************
  272.  
  273.     NAME
  274.     do_unmap
  275.  
  276.     PARAMETER
  277.     void
  278.  
  279.     RESULT
  280.     -/-
  281.  
  282.     RETURN
  283.     void
  284.  
  285.     DESCRIPTION
  286.     command interface for keyhashes/unmapkey
  287.  
  288.     NOTES
  289.     for interface with [X]DME version < 1.70
  290.  
  291.     BUGS
  292.  
  293.     EXAMPLES
  294.  
  295.     SEE ALSO
  296.     do_map, keyhashes/unmapkey
  297.  
  298.     INTERNALS
  299.  
  300.     HISTORY
  301.     14-Dec-92  b_null created
  302.  
  303. ******************************************************************************/
  304.  
  305. void do_unmap (void)
  306. {
  307.     unmapkey ( currenthash(), GetArg(1) );
  308. } /* do_unmap */
  309.  
  310.  
  311.  
  312. /*****************************************************************************
  313.  
  314.     NAME
  315.     do_keysave
  316.  
  317.     PARAMETER
  318.     void
  319.  
  320.     RESULT
  321.     -/-
  322.  
  323.     RETURN
  324.     void
  325.  
  326.     DESCRIPTION
  327.     command interface for keyhashes/savemap
  328.  
  329.     NOTES
  330.     for interface with [X]DME version < 1.70
  331.  
  332.     BUGS
  333.  
  334.     EXAMPLES
  335.  
  336.     SEE ALSO
  337.     do_keyload, keyhashes/savemap
  338.  
  339.     INTERNALS
  340.  
  341.     HISTORY
  342.     14-Dec-92  b_null created
  343.  
  344. ******************************************************************************/
  345.  
  346. void do_keysave (void)
  347. {
  348.     keysave ( currenthash(), GetArg(1) );
  349. } /* do_keysave */
  350.  
  351.  
  352.  
  353. /*****************************************************************************
  354.  
  355.     NAME
  356.     do_keyload
  357.  
  358.     PARAMETER
  359.     void
  360.  
  361.     RESULT
  362.     -/-
  363.  
  364.     RETURN
  365.     void
  366.  
  367.     DESCRIPTION
  368.     command interface for keyhashes/loadmap
  369.  
  370.     NOTES
  371.     for interface with [X]DME version < 1.70
  372.  
  373.     BUGS
  374.  
  375.     EXAMPLES
  376.  
  377.     SEE ALSO
  378.     do_keysave, keyhashes/loadmap
  379.  
  380.     INTERNALS
  381.  
  382.     HISTORY
  383.     14-Dec-92  b_null created
  384.  
  385. ******************************************************************************/
  386.  
  387. void do_keyload (void)
  388. {
  389.     keyload ( currenthash(), GetArg(1) );
  390. } /* do_keyload */
  391.  
  392.  
  393.  
  394. /*****************************************************************************
  395.  
  396.     NAME
  397.     do_qualifier
  398.  
  399.     PARAMETER
  400.     void
  401.  
  402.     RESULT
  403.     -/-
  404.  
  405.     RETURN
  406.     void
  407.  
  408.     DESCRIPTION
  409.     command interface for keyaddes/qualifier
  410.  
  411.     NOTES
  412.     for interface with [X]DME version > 1.70
  413.  
  414.     BUGS
  415.  
  416.     EXAMPLES
  417.  
  418.     SEE ALSO
  419.     keyhashes/qualifier
  420.  
  421.     INTERNALS
  422.  
  423.     HISTORY
  424.     16 Dec 1992 b_null created
  425.  
  426. ******************************************************************************/
  427.  
  428. void do_qualifier (void)
  429. {
  430.     qualifier (GetArg(1));
  431. } /* do_qualifier */
  432.  
  433.  
  434. char * keyspectomacro (char * str)
  435. {
  436.     return (keyspec2macro(currenthash(), str));
  437. } /* keyspectomacro */
  438.  
  439.  
  440.  
  441. /*****************************************************************************
  442.  
  443.     NAME
  444.     do_new_keytable
  445.  
  446.     PARAMETER
  447.     void
  448.  
  449.     RESULT
  450.     -/-
  451.  
  452.     RETURN
  453.     void
  454.  
  455.     DESCRIPTION
  456.     command interface for keyaddes/qualifier
  457.  
  458.     NOTES
  459.     <never tested>
  460.  
  461.     BUGS
  462.     <none known>
  463.  
  464.     EXAMPLES
  465.  
  466.     SEE ALSO
  467.  
  468.     INTERNALS
  469.  
  470.     HISTORY
  471.     28 Jan 1993  b_null created
  472.  
  473. ******************************************************************************/
  474.  
  475. void do_new_keytable (void)
  476. {
  477.     Ep->keytable = new_keytable (GetArg(1), 1);
  478. } /* do_new_keytable */
  479.  
  480.  
  481.  
  482. /*****************************************************************************
  483.  
  484.     NAME
  485.     do_del_keytable
  486.  
  487.     PARAMETER
  488.     void
  489.  
  490.     RESULT
  491.     -/-
  492.  
  493.     RETURN
  494.     void
  495.  
  496.     DESCRIPTION
  497.     command interface for keyaddes/qualifier
  498.  
  499.     NOTES
  500.     <never tested>
  501.  
  502.     BUGS
  503.     <none known>
  504.  
  505.     EXAMPLES
  506.  
  507.     SEE ALSO
  508.  
  509.     INTERNALS
  510.  
  511.     HISTORY
  512.     28 Jan 1993  b_null created
  513.  
  514. ******************************************************************************/
  515.  
  516. void do_del_keytable (void)
  517. {
  518.     KEYTABLE * kt = currenthash ();
  519.     ED         * ep;
  520.  
  521.     for (ep = GetHead (&DBase); ep; ep = GetSucc (ep)) {
  522.     if (ep->keytable == kt) {
  523.         ep->keytable = NULL;
  524.     } /* if */
  525.     } /* for */
  526.  
  527.     delete_keytable (kt, 0);
  528. } /* do_del_keytable */
  529.  
  530.  
  531.  
  532. /*****************************************************************************
  533.  
  534.     NAME
  535.     do_use_keytable
  536.  
  537.     PARAMETER
  538.     void
  539.  
  540.     RESULT
  541.     -/-
  542.  
  543.     RETURN
  544.     void
  545.  
  546.     DESCRIPTION
  547.     command interface for keyaddes/qualifier
  548.  
  549.     NOTES
  550.     <never tested>
  551.  
  552.     BUGS
  553.     <none known>
  554.  
  555.     EXAMPLES
  556.  
  557.     SEE ALSO
  558.  
  559.     INTERNALS
  560.  
  561.     HISTORY
  562.     28 Jan 1993  b_null created
  563.  
  564. ******************************************************************************/
  565.  
  566. void do_use_keytable (void)
  567. {
  568.     KEYTABLE * kt = get_keytable (GetArg (1));
  569.  
  570.     if (kt) {
  571.     Ep->keytable = kt;
  572.     } /* if */
  573. } /* do_use_keytable */
  574.  
  575.  
  576.  
  577. /*****************************************************************************
  578.  
  579.     NAME
  580.     currenthash
  581.  
  582.     PARAMETER
  583.     void;
  584.  
  585.     RESULT
  586.     the current keytable
  587.  
  588.     RETURN
  589.     void;
  590.  
  591.     DESCRIPTION
  592.     An interface to the current ED's window
  593.  
  594.     NOTES
  595.     This function could easiliy be replaced by a macro
  596.  
  597.     HISTORY
  598.     26-08-93    b_noll  created
  599.  
  600. ******************************************************************************/
  601.  
  602. void * currenthash(void)
  603. {
  604.     /* return(onlyhash); */
  605.  
  606.     if ((Ep == NULL) || (Ep->keytable == NULL)) {
  607.     return (get_keytable (NULL));
  608.     } /* if */
  609.     return (Ep->keytable);
  610. } /* currenthash */
  611.  
  612. /*****************************************************************************
  613.  
  614.     NAME
  615.     keyfind
  616.     keygethelp
  617.     keysethelp
  618.     keygetcommand
  619.     keysetcommand
  620.     keycall
  621.  
  622.     PARAMETER
  623.  
  624.     RESULT
  625.  
  626.     RETURN
  627.  
  628.     DESCRIPTION
  629.     interfaces to support handles used by the
  630.     STATIC Command Interface
  631.     in order to enable use of COMTREE key
  632.     as well as VARTREE keycomm/keyhelp
  633.  
  634.     NOTES
  635.     <never tested>
  636.  
  637.     BUGS
  638.     <none known>
  639.  
  640.     EXAMPLES
  641.  
  642.     SEE ALSO
  643.  
  644.     INTERNALS
  645.  
  646.     HISTORY
  647.     05-08-94 null created
  648.  
  649. ******************************************************************************/
  650.  
  651. #ifdef STATIC_COM
  652.  
  653. Prototype APTR keyfind (char *name);
  654. APTR keyfind (char *name) {
  655.     return findhash(currenthash(), name);
  656. } /* keyfind */
  657.  
  658. Prototype char *keygethelp(APTR handle);
  659. char *keygethelp(APTR handle) {
  660.     return ((HASH *)handle)->help;
  661. } /* keygethelp */
  662.  
  663. Prototype char *keygetcommand(APTR handle);
  664. char *keygetcommand(APTR handle) {
  665.     return ((HASH *)handle)->com;
  666. } /* keygetcommand */
  667.  
  668. Prototype char *keysetcommand(APTR handle, char *val);
  669. char *keysetcommand(APTR handle, char *val) {
  670.     char *ptr;
  671.     if (ptr = DupFunc(val)) {
  672.     DeallocFunc(((HASH *)handle)->com);
  673.     ((HASH *)handle)->com = ptr;
  674.     return TRUE;
  675.     } /* if */
  676.     nomemory();
  677.     return FALSE;
  678. } /* keysetcommand */
  679.  
  680. Prototype char *keysethelp (APTR handle, char *val);
  681. char *keysethelp (APTR handle, char *val) {
  682.     char *ptr;
  683.     if (ptr = DupFunc(val)) {
  684.     DeallocFunc(((HASH *)handle)->help);
  685.     ((HASH *)handle)->help = ptr;
  686.     return TRUE;
  687.     } /* if */
  688.     nomemory();
  689.     return FALSE;
  690. } /* keysethelp */
  691.  
  692. Prototype int keycall (APTR handle);
  693. int keycall (APTR handle) {
  694.     char *ptr;
  695.     if (ptr = strdup(keygetcommand(handle))) {
  696.     retval = do_command(ptr);
  697.     free (ptr);
  698.     return OK;
  699.     } /* if */
  700.     nomemory();
  701.     return FALSE;
  702. } /* keycall */
  703.  
  704. #endif STATIC_COM
  705.  
  706.  
  707. #ifdef PATCH_NULL /* PATCH_NULL < 24-06-94 */
  708.  
  709. /* **************************************************
  710.     STATIC XDME Command Interface
  711. ************************************************** //
  712.  
  713. //        Name    #Args Function        Flags
  714. :FX:COMMAND keyload    1 do_keyload
  715. :FX:COMMAND keysave    1 do_keysave
  716. :FX:COMMAND newkeytable 1 do_new_keytable
  717. :FX:COMMAND remkeytable 1 do_rem_keytable
  718. :FX:COMMAND usekeytable 1 do_use_keytable
  719. :FX:COMMAND map     2 do_map
  720. :FX:COMMAND unmap    1 do_unmap
  721.  
  722. //        Name  Pri Lock         Unlock   Call     NArgs
  723. :FX:COMTREE key     0 keyspectomacro return0  do_command return0      Flags=NoHandles
  724.  
  725. //        Name  Pri Lock         Unlock   Get    Set     Unset
  726. :FX:VARTREE key     0 keyspectomacro return0  strdup return0 return0  Flags=NoHandles
  727.  
  728. // **************************************************
  729.     DYNAMIC XDME Command Interface
  730. ************************************************** */
  731.  
  732. static const
  733. struct CommandNode KEY_Commands[] =
  734. {
  735.     {ENODE("keyload"),       1,        CF_VWM|CF_ICO, (FPTR)do_keyload      }, /* tester */
  736.     {ENODE("keysave"),       1,        CF_VWM|CF_ICO, (FPTR)do_keysave      }, /* tester */
  737.     {ENODE("newkeytable"),   1, CF_VWM|CF_ICO|CF_COK, (FPTR)do_new_keytable },
  738.     {ENODE("remkeytable"),   1, CF_VWM|CF_ICO|CF_COK, (FPTR)do_del_keytable },
  739.     {ENODE("usekeytable"),   1, CF_VWM|CF_ICO|CF_COK, (FPTR)do_use_keytable },
  740.     {ENODE("map"),           2,        CF_VWM|CF_ICO, (FPTR)do_map          },
  741.     {ENODE("unmap"),         1, CF_VWM|CF_COK|CF_ICO, (FPTR)do_unmap        },
  742. #if 0
  743.     {ENODE("savemap"),       1, CF_VWM|CF_COK|CF_ICO, (FPTR)do_savemap      },         /* checks com name for mode */
  744.     {ENODE("savesmap"),      1, CF_VWM|CF_COK|CF_ICO, (FPTR)do_savemap      },
  745. #endif
  746. };
  747.  
  748.  
  749.  
  750. MK_AUTOINIT( KEY_init )
  751. {
  752.     int i;
  753.  
  754.     for (i = sizeof (KEY_Commands)/sizeof (struct CommandNode) - 1;i >= 0; --i)
  755.     COM_Add (&KEY_Commands[i]);
  756.  
  757.  /* COM_AddClass()   ->keyspectomacro */
  758.  /* COM_AddVarClass()->keyspectomacro */
  759. } /* KEY_init */
  760.  
  761.  
  762. #if 0
  763.  
  764. MK_AUTOEXIT( KEY_Exit )
  765. {
  766.     int  i;
  767.     APTR lock;
  768.  
  769.     for (i = sizeof (KEY_Commands)/sizeof (struct CommandNode) - 1; (i >= 0); DEC(i))
  770.     if (lock = COM_Lock (KEY_Commands[i].cn_Name))
  771.         COM_Remove (lock);
  772. } /* KEY_Exit */
  773.  
  774. #endif
  775.  
  776. #endif
  777.  
  778.  
  779. /******************************************************************************
  780. *****  ENDE keycom.c
  781. ******************************************************************************/
  782.